<?php

namespace App\Http\Controllers\CRM\MiniAPP;

use App\Helper\ApiResponseHelper;
use App\Http\Controllers\Controller;
use App\Http\Requests\CRM\MiniAPP\TableTypeRequest;
use App\Http\Resources\CRM\MiniAPP\TableTypeResource;
use App\Models\FakeTableType;
use Illuminate\Http\Request;

class TableTypeController extends Controller
{
    public function getList()
    {
        $types = FakeTableType::latest()->get();

        return TableTypeResource::collection($types);
    }

    public function getInfo(FakeTableType $type)
    {
        return new TableTypeResource($type);
    }

    public function create(TableTypeRequest $request)
    {
        $type = FakeTableType::create($request->only([
            'name', 'price'
        ]));

        return new TableTypeResource($type);
    }

    public function edit(FakeTableType $type, TableTypeRequest $request)
    {
        $type->update($request->only([
            'name', 'price'
        ]));

        return new TableTypeResource($type);
    }

    public function remove(FakeTableType $type)
    {
        $type->delete();

        return ApiResponseHelper::json([]);
    }
}
